import Utils from '@/utils/index'
import proxy from '@/network/proxy'

/**
 * 跳转聊天界面
 * @param item 会话信息
 * @param type 单聊1或群聊2
 * @param chatSysAddr 在线交流地址
 * @param token token
 * @param lg_ic 身份码
 * @param schoolId 学校Id
 * @param e 事件对象
 * @returns {undefined}
 */
function useToChatPage(item, type,chatSysAddr,token,lg_ic,schoolId, e?){
    e && e.stopPropagation()
    const { avatarPath, photoPath, userType } = item
    let chatId = type == 2 ? item.groupId : (item.userId || item.receiverId);
    let chatName = type == 2 ? item.groupName : (item.userName || item.receiverName);
    let chatUrl = ''
    const jumpAvatar=encodeURIComponent(avatarPath || photoPath || '')
    if(!chatSysAddr){
        Taro.showToast({
            title:'暂无在线交流地址，敬请期待',
            icon:'none'
        })
        return
    }
    chatUrl = `${chatSysAddr}/mobile/index.html?lg_tk=${token}&lg_ic=${lg_ic}&chatId=${chatId}&chatName=${chatName}&chatType=${type}&env=${Utils.getSystemInfo()}&schoolId=${schoolId}&jumpPage=1&chatPhoto=${jumpAvatar}&userType=${userType || '4'}`
    if (process.env.NODE_ENV === 'development') {
        chatUrl = `http://192.168.129.86:10088/?lg_tk=${token}&lg_ic=${lg_ic}&chatId=${chatId}&chatName=${chatName}&chatType=${type}&env=${Utils.getSystemInfo()}&schoolId=${schoolId}&jumpPage=1&chatPhoto=${jumpAvatar}&userType=${userType || '4'}`
    } 
    if (process.env.NODE_ENV === 'production'&&Utils.getSystemInfo() === 'weapp') {
       chatUrl = proxy.transmitUrlToVisit(chatUrl)
    }
  
    window.open(chatUrl, "_self")
}

export default useToChatPage